<template>
  <div class="fczt-bars">
    <div class="bar-item" v-for="(item,index) in data" :key="index">
      <div class="bar-item-label">{{item.label}}</div>
      <div class="bar-item-progress">
        <div class="bar-item-progress__inner" :style="{width: item.per+'%'}"></div>
      </div>
      <div class="bar-item-suffix">{{item.value}}个</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'fczt-bars',
  props: {
    list: Array
  },
  data() {
    return {
      data: []
    }
  },
  methods: {
    init() {
     const d = [].concat(this.list)
      let total = 0
      total = d.map(o => Number(o.value)).reduce((a,b) => a+b)

      d.map((o, i) => {
        let per = o.value / total * 100
        o.per = per
      })
      this.data = d

    }
  },
  mounted() {
    this.init()
  }
}
</script>

<style lang="scss" scoped>
.fczt-bars {
  margin: 0 10px;

  .bar-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 40px;
    border-bottom: 1px solid #174d96;

    &-label {
      width: 70px;
    }
    &-progress {
      flex: 1;
      position: relative;
      height: 8px;
      background-color: rgba(255, 255, 255, .2);
      border-radius: 10px;

      &__inner {
        border-radius: 10px;
        position: absolute;
        left: 0;
        height: 100%;
        transition: all .3s linear;
        background: linear-gradient(90deg, rgba(35, 228, 171, 1) 0%, rgba(35, 228, 171, 1) 0%, rgba(9, 174, 233, 1) 100%, rgba(9, 174, 233, 1) 100%);
      }
    }

    &-suffix {
      width: 40px;
      text-align: right;
    }


  }

}
</style>
